#include <cstdio>

int main() {
	int count = 0;
	for (int i=10000; i<=99999; i++) {
		int t = i;
		if (t/10000 != 4) {
			t %= 10000;
			if (t/1000 != 4) {
				t %= 1000;
				if (t/100 != 4) {
					t %= 100;
					if (t/10 != 4) {
						t %= 10;
						if (t != 4) {
							count++;
						}
					}
				}
			}
		}
	}
	printf("%d\n", count);
}
